import axios from 'axios'
import storage from '@/utils/storage'

import { baseDomain } from '@/env.js'
axios.defaults.baseURL = baseDomain
axios.defaults.headers.common['Authorization'] = `Bearer ${storage.getItem('token')}`
axios.defaults.headers.common['Content-Type'] = 'application/json'

// 返回一个Promise(发送post请求)
export function fetch (url, params) {
  return new Promise((resolve, reject) => {
    axios.post(url, params)
      .then(response => {
        resolve(response.data)
      }, err => {
        reject(err)
      })
      .catch((error) => {
        reject(error)
      })
  })
}
